# -*- coding: utf-8 -*-
# standard
import os
import sys
import json
from datetime import datetime, timedelta

# third
import requests

# local
_P_PATH =  os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if _P_PATH not in sys.path:
    sys.path.append(_P_PATH)
from models.base_model import TASK_AUTHORIZATION


"""
@Title:   
@File: 模拟发送内网节点信息.py
@Author: walle 2025年01日06日 13时42分30秒
@Version: 1.0.0
@Desc: 
"""


def send_lan_node_offline_alert():
    """
    模拟发送内网节点离线告警
    """
    url = "http://127.0.0.1:12005/v1/event/lan_node"
    headers = {
        'Content-Type': 'application/json',
        'Authorization': TASK_AUTHORIZATION,
    }
    file_path = os.path.join(_P_PATH, 'examples', '模拟Lan信息.json')
    with open(file_path, mode='r', encoding='utf-8') as f:
        raw = json.load(f)
        data = raw['节点离线2']
        now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        data['alert_time'] = now
        data['push_time'] = now 
    resp = requests.post(url=url, json=data, headers=headers)
    resp = resp.text
    print(resp)


def send_lan_node_offline_recovery():
    """
    模拟发送内网节点离线恢复
    """
    url = "http://127.0.0.1:12005/v1/event/lan_node"
    headers = {
        'Content-Type': 'application/json',
        'Authorization': TASK_AUTHORIZATION,
    }
    file_path = os.path.join(_P_PATH, 'examples', '模拟Lan信息.json')
    with open(file_path, mode='r', encoding='utf-8') as f:
        raw = json.load(f)
        data = raw['节点离线恢复2']
        now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        data['alert_time'] = now
        data['push_time'] = now 
    resp = requests.post(url=url, json=data, headers=headers)
    resp = resp.text
    print(resp)



if __name__ == '__main__':
    send_lan_node_offline_alert()
    # send_lan_node_offline_recovery()
    pass